#!/bin/sh
#chkconfig:2345 81 90
#description:vnc
#processname:vnc
# Simple vnc init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
APP_NAME=x11vnc
EXEC_PATH=/bin/x11vnc
#CONF="/etc/x11vnc.conf"
#CONF="-display :0 -auth /var/run/lightdm/root/:0 -forever -bg -o /var/log/x11vnc.log -rfbauth /etc/x11vnc.pass -rfbport 5900 -noxdamage"
CONF="${auth} ${display} ${rfbauth} ${rfbport} ${logfille} ${args}"
#EXEC_COMMAND=/bin/x11vnc -rfbport 5900 -rfbauth ~/.vnc/passwd  -display :0 -forever -bg -repeat -nowf -o ~/.vnc/x11vnc.log &

vncpid=`ps -ef | grep "$APP_NAME" | grep -v grep | awk -F" " '{print $2}'`
vncwc=`ps -ef | grep "$APP_NAME" | grep -v grep | awk -F" " '{print $8}' | grep vnc | grep -v grep | wc -l`

case "$1" in
start)
	echo "Starting vnc Server..."
	sleep 5
	$EXEC_PATH $CONF &
	echo `ps -ef | grep "$APP_NAME" | grep -v grep | awk -F" " '{print $2}'`
;;
stop)
	echo "Stopping vnc Server..."
	killall -9 x11vnc
;;
restart)
	killall -9 x11vnc
	$EXEC_PATH $CONF &
;;
status)
      if [ "${vncwc}" = "1" ];
      then
		echo "Vnc is running(pid ${vncpid})"
      else
		echo "Vnc is not running"
      fi
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac
exit 0